import {ADD_COUNTER,ADD_TO_CART} from './mutation-types'

export default {
  // 添加商品信息
  addCart(content,payload){
    return new Promise((resolve,reject)=>{
      let oldProduct = content.state.cartList.find(item=>item.iid === payload.iid)
      if(oldProduct){
        // oldProduct.count += 1
        content.commit(ADD_COUNTER,oldProduct)
        resolve('当前商品数量+1')
      }else{
        payload.count = 1
        // content.state.cartList.push(payload)
        content.commit(ADD_TO_CART,payload)
        resolve('添加了新的商品')
      }
    })


    // if(oldProduct){
    //   // oldProduct.count += 1
    //   content.commit('AddCounter',oldProduct)
    // }else{
    //   payload.count = 1
    //   // content.state.cartList.push(payload)
    //   content.commit('addToCart',payload)
    // }
  }
}
